package smarties.style;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Stroke;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import smarties.SmartEdge;
import smarties.SmartNode;

import com.touchgraph.graphlayout.TGPanel;

@XmlRootElement(name = "circleStyle")
public class CircleStyle extends SmartStyle
{
	private int		maxRadius	= 70;

	@XmlTransient
	private int		radius		= 50;

	@XmlTransient
	private int		border		= 3;

	private Stroke	stroke		= new BasicStroke(this.border);

	protected Stroke getStroke()
	{
		return this.stroke;
	}

	@XmlElement(name = "radius")
	public int getMaxRadius()
	{
		return this.maxRadius;
	}

	public void setMaxRadius(int maxRadius)
	{
		this.maxRadius = maxRadius;
	}

	@XmlTransient
	public int getRadius()
	{
		return this.radius;
	}

	public void setRadius(int radius)
	{
		this.radius = radius;
	}

	@XmlElement(name = "border")
	public int getBorder()
	{
		return this.border;
	}

	public void setBorder(int border)
	{
		this.border = border;
		this.stroke = new BasicStroke(this.border);
	}

	@Override
	public void setPercentVisualisation(int percent)
	{
		this.setRadius((int) (percent * this.maxRadius / 100f));
		super.setPercentVisualisation(percent);
	}

	@Override
	public void paintNodeBody(SmartNode node, Graphics2D g,
			TGPanel<SmartNode, SmartEdge> tgPanel)
	{
		if (node.isSelected())
		{
			g.setColor(this.getSmartColor().getColor());
		}
		else
		{
			g.setColor(SmartNode.getUnselectedSmartColor().getColor());
		}

		if (this.getRadius() < node.getHeight()
				&& this.getRadius() < node.getWidth())
		{
			this.radius = node.getHeight();
		}

		int ix = (int) node.drawx;
		int iy = (int) node.drawy;

		int twoRadius = 2 * this.radius;
		g.fillOval(ix - this.radius, iy - this.radius, twoRadius, twoRadius);

		Stroke previousStroke = g.getStroke();
		g.setStroke(this.stroke);

		g.drawOval(ix - this.radius, iy - this.radius, twoRadius, twoRadius);

		g.setStroke(previousStroke);

		node.defaultPointNodeBody(g, tgPanel);
	}
}
